/*
 * @Author: giky
 * @Date: 2018-12-05 08:59:54
 * @Last Modified by: giky
 * @Last Modified time: 2019-02-22 09:37:13
 */

//一般直接写在一个js文件中
layui
  .config({
    base: "../../layuiadmin/" //静态资源所在路径
  })
  .extend({
    setter: "config", //配置模块
    admin: "lib/admin", //核心模块
    view: "lib/view", //视图渲染模块
    zkMap: "../views/map/js/zkMap", //监督指挥
    leftTabScroll: "../views/map/js/leftTabScroll", //左侧tab滚动
    echarts: 'lib/extend/echarts',
    tax: 'modules/tax',
    rangeSlider: "modules/rangeSlider"//时间轴插件
  })
  .define(["form", 'laydate', "element", "setter", "admin", "zkMap", "rangeSlider", "leftTabScroll", 'echarts', 'tax'], function () {
    var leftTabScroll = layui.leftTabScroll;
    var leftTabScroll2 = layui.leftTabScroll;
    var admin = layui.admin;
    var laydate = layui.laydate;
    var $ = layui.$;
    // 执行时间轴实例
    var custom_values1 = ["2011.5.1", "2011.5.2", "2011.5.3", "2011.5.4", "2011.5.5", "2011.5.6", "2011.5.7"];
    var my_from1 = custom_values1.indexOf('2011.5.3');
    var my_to1 = custom_values1.indexOf('2011.5.6');
    function test(data) {
      console.log(data)
    }
    $("#demo_1").ionRangeSlider({
      type: "double",
      grid: true,
      skin: "round",
      from: my_from1,
      to: my_to1,
      values: custom_values1,
      onChange: function (data) {
        var bounds = map.getBounds();
        var sw = bounds.getSouthWest();
        var ne = bounds.getNorthEast();
        var lngSpan = Math.abs(sw.lng - ne.lng);
        var latSpan = Math.abs(ne.lat - sw.lat);
        for (var i = 0; i < 5; i++) {
          var point = new BMap.Point(sw.lng + lngSpan * (Math.random() * 0.7), ne.lat - latSpan * (Math.random() * 0.7));
          addMarker(point);
        }
      },
    });
    var custom_values2 = [2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019];
    var my_from2 = custom_values2.indexOf(2013);
    $("#demo_2").ionRangeSlider({
      grid: true,
      skin: "round",
      from: my_from2,
      values: custom_values2
    });
    //执行一个laydate实例
    laydate.render({
      elem: '#date1'
      , range: true //或 range: '~' 来自定义分割字符
    });
    leftTabScroll.init({
      elem: '.tag_list_bk'
    });
    layui.admin.events = $.extend(layui.admin.events, {
      popWin: function () {
        console.log(123)
      }
    });
    //全屏监听
    $(".fullScreenBtn").click(function () {
      var docElm = window.frameElement;
      var elm = document.documentElement;
      var requestMethod = elm.requestFullScreen || elm.webkitRequestFullScreen || elm.mozRequestFullScreen || elm.msRequestFullscreen;
      if (elm.msRequestFullscreen) {
        elm = docElm;
      }
      requestMethod.call(elm);

      if (!isFullscreenForNoScroll()) {
        if (!docElm) return;
        (docElm.requestFullscreen && docElm.requestFullscreen()) ||
          (docElm.mozRequestFullScreen && docElm.mozRequestFullScreen()) ||
          (docElm.webkitRequestFullscreen && docElm.webkitRequestFullscreen()) ||
          (docElm.msRequestFullscreen && docElm.msRequestFullscreen());
      } else {
        // 判断各种浏览器，找到正确的方法
        document.exitFullscreen ? document.exitFullscreen() :
          document.mozCancelFullScreen ? document.mozCancelFullScreen() :
            document.webkitExitFullscreen ? document.webkitExitFullscreen() : '';
      }

    });
    $(window).resize(function () {
      if (isFullscreenForNoScroll()) {
        $(".fullScreenBtn").find("i").html("&#xe7cd;");
      } else {
        $(".fullScreenBtn").find("i").html("&#xe64f;");
      }
    });

    function isFullscreenForNoScroll() {
      return document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen;
    }

  });
